package com.station.administrators.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.open.capacity.common.model.OrderModel;
import com.open.capacity.common.web.Result;
import com.station.administrators.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 订单管理
 * @Description: TODO
 * @date 2021/6/25/9:48
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @ApiOperation("修改订单")
    @PostMapping("/update")
    public Object update(@RequestBody OrderModel orderModel){
        orderService.update(orderModel);
        return Result.succeed("成功！");
    }
    @ApiOperation("修改订单状态")
    @PostMapping("/updates")
    public Object updates(@RequestBody OrderModel orderModel){
        orderService.updates(orderModel);
        return Result.succeed("成功！");
    }
    @ApiOperation("删除订单")
    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable Long id){
        orderService.delete(id);
        return Result.succeed("删除成功！");
    }
    @ApiOperation("根据id查询订单")
    @GetMapping("/findById")
    public Object findById(Long id){
        OrderModel orderModel=orderService.findById(id);
        return Result.succeed(orderModel,"查询成功！");
    }
    @ApiOperation("查询所有订单")
    @GetMapping("/findAll")
    public Object findAll(OrderModel orderModel){
        List<OrderModel> orderList =orderService.findAll(orderModel);
        Integer count=orderService.getCount(orderModel);
        Map<String,Object> map=new HashMap<>();
        map.put("orderList",orderList);
        map.put("count",count);
        return Result.succeed(map,"查询成功！");
    }

}
